package com.atguigu.gmall.mq.receiver;

import com.atguigu.gmall.mq.config.DeadLetterMqConfig;
import com.rabbitmq.client.Channel;
import lombok.SneakyThrows;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class DeadLetterReceiver {

    @RabbitListener(queues = DeadLetterMqConfig.queue_dead_2)
    @SneakyThrows
    public void processMessage(String msg, Message message, Channel channel){

        //时间格式化对象
        SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        System.out.println("我收到消息的时间为\t"+format.format(new Date()));

        System.out.println("我收到的消息为："+msg);




        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }
}
